Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgs: [
      "../../image/goods01.jpg",
      "../../image/goods02.jpg",
      "../../image/goods03.jpg",
      "../../image/goods04.jpg"
    ],
    num: 90,
    shangpinId:"",
    hiddenName: true,
    boolen: false,
    eachBoolen: false,

    iconArr: [{
        icon_picture: "../../image/icon-fujin.png",
        icon_name: "育婴",
        url: "/pages/fujin/fujin"
      },
      {
        icon_picture: "../../image/icon-fuli.png",
        icon_name: "生活用品",
        url: "/pages/fuli/fuli"
      },

      {
        icon_picture: "../../image/icon-qiandao.png",
        icon_name: "耳机",
        url: "/pages/zhoubian/zhoubian"
      },
      {
        icon_picture: "../../image/icon-qinzi.png",
        icon_name: "摄影",
        url: "/pages/qingzi/qingzi"
      },
      {
        icon_picture: "../../image/icon-tiyu.png",
        icon_name: "数码",
        url: "/pages/tiyu/tiyu"
      },
      {
        icon_picture: "../../image/icon-xingxing.png",
        icon_name: "乐器",
        url: "/pages/xinxi/xinxi"
      },
      {
        icon_picture: "../../image/icon-zhanhui.png",
        icon_name: "品牌",
        url: "/pages/zhanhui/zhanhui"
      },
    ],
    goodsArr: [
    ],
    goodsReverse: [],
    shousuo: [],
   
    imgUrls: [
      '../../image/slide-1.jpg',
      '../../image/slide-2.jpg',
      '../../image/slide-3.jpg',
      '../../image/slide-4.jpg',
      '../../image/slide-5.jpg',
    ],
    indicatorDots: true, //是否显示面板指示点
    autoplay: true, //是否自动播放
    interval: 3000, //停留时间间隔
    duration: 1000, //播放时长
    previousMargin: '50px', //前边距，可用于露出前一项的一小部分，接受 px 和 rpx 值
    nextMargin: '50px', //后边距，可用于露出后一项的一小部分，接受 px 和 rpx 值
    circular: true, //是否采用衔接滑动
    currentSwiperIndex: 0, //swiper当前索引
    inputContent: "",




  },

  // }),
  dianji() {
    this.setData({
      boolen: !this.data.boolen,
    })
    console.log(this.data.boolen);
    if (this.data.boolen) {
      this.setData({
        goodsReverse: this.data.goodsArr.reverse(),
      })
    } else {
      this.setData({
        goodsArr: this.data.goodsArr.reverse()
      })
    }
  },




  swiperBindchange(e) {
    this.setData({
      currentSwiperIndex: e.detail.current
    })
  },
  clickMe: function (e) {
    this.setData({
      hiddenName: !this.data.hiddenName
    })
  },
  onLoad: function (options) {
    this.getGoodsData();
    this.getGoodsBanner();
    console.log(this.data.goodsArr)
  },
  getGoodsData() {
    let _this = this;
    // _this.setData({
    //   num: _this.data.num + 1,
    // })

    wx.request({

      url: 'https://api-hmugo-web.itheima.net/api/public/v1/goods/search?"cid"="10"&pagenum=1879&pagesize=20', //仅为示例，并非真实的接口地址

      header: {
        'content-type': 'application/json' // 默认值
      },
      // data:{
      //   "cid":cid,
      //   pagenum:pagenum,
      //   pagesize:pagesize,
      // } , 
      success(res) {
        let goodslist = res.data.message.goods;
        let lists = [];
        goodslist.forEach(item => {
          let {
            goods_id,
            goods_name,
            goods_small_logo,
            goods_price
          } = item;
          let data = {
            id: goods_id,
            goods: goods_small_logo,
            name: goods_name,
            price: goods_price

          }
          if (goods_small_logo) {
            lists.push(data);
          }


        })
        let getInputDetail = lists.map(item => item.name);
        _this.setData({
          goodsArr: lists,
          shousuo: getInputDetail

        })
        console.log(_this.data.goodsArr);
        console.log(_this.data.shousuo);

      }
    })

  },
  getInput(options) {
    console.log(123)
    console.log(options.detail.value);

    this.setData({
      inputContent: options.detail.value,

    })
    console.log(this.data.inputContent);
    let content = this.data.inputContent;
    let allContent = this.data.shousuo;
    let index = allContent.findIndex(item => item.indexOf(content) > -1);
    console.log(index);

    let contentId=this.data.goodsArr[index].id;
   
    this.setData({
      shangpinId:contentId,
    })
    console.log(this.data.shangpinId);

  },
  qiandao(options) {

    if (options.currentTarget.dataset.id == 2) {
      console.log(123);
      this.setData({
        eachBoolen: !this.data.eachBoolen,
      })
    }

  },
  // queryData(options) {
  //   console.log(123);
  //   let content = this.data.inputContent;
  //   let allContent = this.data.shousuo;
  //   let index = allContent.findIndex(item => item.indexOf(content) > -1);
  //   console.log(index);

  //   let contentId=this.data.goodsArr[index].id;
   
  //   this.setData({
  //     shangpinId:contentId,
  //   })
  //   console.log(this.data.shangpinId);

  // },
  getGoodsBanner() {
    let _this = this;
    wx.request({
      url: "https://api-hmugo-web.itheima.net/api/public/v1/home/swiperdata",
      header: {
        "content-type": "application/json"
      },
      success(res) {
        let goodsBanner = res.data.message;
        console.log(goodsBanner)
        let lists = [];
        goodsBanner.forEach(item => {
          let {
            image_src
          } = item;

          lists.push(image_src);
        })
        _this.setData({
          imgs: lists,
        })


      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getGoodsData();
    console.log(this.data.goodsArr);
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})